//@version=6
indicator("Complete Harmonic Pattern)", overlay = true, max_lines_count = 500, max_labels_count = 500)

//------------------------ INPUTS ------------------------//
// Timeframes string (not deeply used, just UI hint)
timeframes = input.string("1,5,15,30,60,240,D", "Timeframes to Scan", tooltip = "Comma-separated timeframes: 1,5,15,30,60,240,D,W")

// Pattern types to show
showGartley      = input.bool(true,  "Show Gartley")
showBat          = input.bool(true,  "Show Bat")
showButterfly    = input.bool(true,  "Show Butterfly")
showCrab         = input.bool(true,  "Show Crab")
showShark        = input.bool(true,  "Show Shark")
showCypher       = input.bool(true,  "Show Cypher")
showFiveZero     = input.bool(true,  "Show 5-0")
showABCD         = input.bool(true,  "Show AB=CD")
showThreeDrives  = input.bool(true,  "Show Three Drives")
showDeepCrab     = input.bool(true,  "Show Deep Crab")
showAltBat       = input.bool(true,  "Show Alternative Bat")

showBull         = input.bool(true,  "Show Bullish Patterns")
showBear         = input.bool(true,  "Show Bearish Patterns")
strength         = input.int(3, "Fractal Strength (bars left/right)", minval = 1, maxval = 10)
showFractals     = input.bool(false, "Show Fractals (pivot points)")

// Display options
alertOnPattern   = input.bool(true,  "Alert on New Pattern")
showMTFDashboard = input.bool(true,  "Show MTF Dashboard")

// --- Gartley (XA-based ratios) --- //
gbBMin  = input.float(0.55, "Gartley B Min (XA)",  minval = 0.30, maxval = 1.00, step = 0.01)
gbBMax  = input.float(0.72, "Gartley B Max (XA)",  minval = 0.40, maxval = 1.00, step = 0.01)
gbCMin  = input.float(0.38, "Gartley C Min (AB)",  minval = 0.30, maxval = 1.27, step = 0.01)
gbCMax  = input.float(1.00, "Gartley C Max (AB)",  minval = 0.40, maxval = 1.27, step = 0.01)
gbDMin  = input.float(0.55, "Gartley D Min (XA)",  minval = 0.30, maxval = 1.00, step = 0.01)
gbDMax  = input.float(1.00, "Gartley D Max (XA)",  minval = 0.40, maxval = 1.00, step = 0.01)

// --- Bat --- //
batBMin = input.float(0.38, "Bat B Min (XA)",      minval = 0.30, maxval = 1.00, step = 0.01)
batBMax = input.float(0.55, "Bat B Max (XA)",      minval = 0.40, maxval = 1.00, step = 0.01)
batCMin = input.float(0.38, "Bat C Min (AB)",      minval = 0.30, maxval = 1.62, step = 0.01)
batCMax = input.float(1.62, "Bat C Max (AB)",      minval = 0.40, maxval = 1.62, step = 0.01)
batDMin = input.float(0.50, "Bat D Min (XA)",      minval = 0.30, maxval = 1.00, step = 0.01)
batDMax = input.float(1.00, "Bat D Max (XA)",      minval = 0.40, maxval = 1.00, step = 0.01)

// --- Butterfly --- //
btBMin  = input.float(0.55, "Butterfly B Min (XA)", minval = 0.30, maxval = 1.00, step = 0.01)
btBMax  = input.float(0.90, "Butterfly B Max (XA)", minval = 0.40, maxval = 1.00, step = 0.01)
btCMin  = input.float(0.38, "Butterfly C Min (AB)", minval = 0.30, maxval = 1.62, step = 0.01)
btCMax  = input.float(1.62, "Butterfly C Max (AB)", minval = 0.40, maxval = 1.62, step = 0.01)
btDMin  = input.float(1.00, "Butterfly D Min (XA)", minval = 1.00, maxval = 1.80, step = 0.01)
btDMax  = input.float(1.38, "Butterfly D Max (XA)", minval = 1.00, maxval = 1.80, step = 0.01)

// --- Crab --- //
cbBMin  = input.float(0.38, "Crab B Min (XA)",      minval = 0.30, maxval = 1.00, step = 0.01)
cbBMax  = input.float(0.65, "Crab B Max (XA)",      minval = 0.40, maxval = 1.00, step = 0.01)
cbCMin  = input.float(0.38, "Crab C Min (AB)",      minval = 0.30, maxval = 1.62, step = 0.01)
cbCMax  = input.float(1.62, "Crab C Max (AB)",      minval = 0.40, maxval = 1.62, step = 0.01)
cbDMin  = input.float(1.25, "Crab D Min (XA)",      minval = 1.00, maxval = 1.80, step = 0.01)
cbDMax  = input.float(1.80, "Crab D Max (XA)",      minval = 1.00, maxval = 2.00, step = 0.01)

// --- Shark --- //
shBMin  = input.float(0.50, "Shark B Min (XA)",     minval = 0.30, maxval = 1.00, step = 0.01)
shBMax  = input.float(0.90, "Shark B Max (XA)",     minval = 0.40, maxval = 1.00, step = 0.01)
shCMin  = input.float(1.13, "Shark C Min (AB)",     minval = 1.00, maxval = 1.62, step = 0.01)
shCMax  = input.float(1.62, "Shark C Max (AB)",     minval = 1.00, maxval = 1.62, step = 0.01)
shDMin  = input.float(0.88, "Shark D Min (XA)",     minval = 0.50, maxval = 1.13, step = 0.01)
shDMax  = input.float(1.13, "Shark D Max (XA)",     minval = 0.50, maxval = 1.13, step = 0.01)

// --- Cypher --- //
cyBMin  = input.float(0.38, "Cypher B Min (XA)",    minval = 0.30, maxval = 1.00, step = 0.01)
cyBMax  = input.float(0.62, "Cypher B Max (XA)",    minval = 0.40, maxval = 1.00, step = 0.01)
cyCMin  = input.float(1.13, "Cypher C Min (AB)",    minval = 1.00, maxval = 1.41, step = 0.01)
cyCMax  = input.float(1.41, "Cypher C Max (AB)",    minval = 1.00, maxval = 1.41, step = 0.01)
cyDMin  = input.float(0.78, "Cypher D Min (XA)",    minval = 0.50, maxval = 1.00, step = 0.01)
cyDMax  = input.float(1.00, "Cypher D Max (XA)",    minval = 0.50, maxval = 1.00, step = 0.01)

// --- 5-0 --- //
fzBMin  = input.float(1.13, "5-0 B Min (XA)",      minval = 1.00, maxval = 1.62, step = 0.01)
fzBMax  = input.float(1.62, "5-0 B Max (XA)",      minval = 1.00, maxval = 1.62, step = 0.01)
fzCMin  = input.float(1.27, "5-0 C Min (AB)",      minval = 1.00, maxval = 2.24, step = 0.01)
fzCMax  = input.float(2.24, "5-0 C Max (AB)",      minval = 1.00, maxval = 2.24, step = 0.01)
fzDMin  = input.float(0.50, "5-0 D Min (XA)",      minval = 0.30, maxval = 1.00, step = 0.01)
fzDMax  = input.float(1.00, "5-0 D Max (XA)",      minval = 0.30, maxval = 1.00, step = 0.01)

// --- AB=CD --- //
abMin   = input.float(0.95, "AB=CD Min Ratio",     minval = 0.80, maxval = 1.20, step = 0.01)
abMax   = input.float(1.05, "AB=CD Max Ratio",     minval = 0.80, maxval = 1.20, step = 0.01)

// --- Three Drives --- //
tdMin   = input.float(1.27, "Three Drives Min",    minval = 1.13, maxval = 1.62, step = 0.01)
tdMax   = input.float(1.62, "Three Drives Max",    minval = 1.13, maxval = 1.62, step = 0.01)

// --- Deep Crab --- //
dcBMin  = input.float(0.38, "Deep Crab B Min (XA)", minval = 0.30, maxval = 1.00, step = 0.01)
dcBMax  = input.float(0.62, "Deep Crab B Max (XA)", minval = 0.40, maxval = 1.00, step = 0.01)
dcCMin  = input.float(0.38, "Deep Crab C Min (AB)", minval = 0.30, maxval = 1.62, step = 0.01)
dcCMax  = input.float(1.62, "Deep Crab C Max (AB)", minval = 0.40, maxval = 1.62, step = 0.01)
dcDMin  = input.float(2.00, "Deep Crab D Min (XA)", minval = 1.62, maxval = 2.24, step = 0.01)
dcDMax  = input.float(2.24, "Deep Crab D Max (XA)", minval = 1.62, maxval = 2.24, step = 0.01)

// --- Alternative Bat --- //
abBMin2 = input.float(0.38, "Alt Bat B Min (XA)",   minval = 0.30, maxval = 1.00, step = 0.01)
abBMax2 = input.float(0.50, "Alt Bat B Max (XA)",   minval = 0.40, maxval = 1.00, step = 0.01)
abCMin2 = input.float(0.38, "Alt Bat C Min (AB)",   minval = 0.30, maxval = 1.62, step = 0.01)
abCMax2 = input.float(1.62, "Alt Bat C Max (AB)",   minval = 0.40, maxval = 1.62, step = 0.01)
abDMin2 = input.float(1.62, "Alt Bat D Min (XA)",   minval = 1.27, maxval = 2.00, step = 0.01)
abDMax2 = input.float(2.00, "Alt Bat D Max (XA)",   minval = 1.27, maxval = 2.00, step = 0.01)

//------------------------ FRACTALS (PIVOTS) ------------------------//
ph   = ta.pivothigh(high, strength, strength)
pl   = ta.pivotlow(low, strength, strength)
isPh = not na(ph)
isPl = not na(pl)

// optional visual fractals
plotshape(showFractals and isPh, title = "Pivot High", style = shape.triangledown, location = location.abovebar, offset = -strength, size = size.tiny, color = color.red)
plotshape(showFractals and isPl, title = "Pivot Low",  style = shape.triangleup,   location = location.belowbar, offset = -strength, size = size.tiny, color = color.lime)

//------------------------ STORE LAST PIVOTS ------------------------//
var float[] pivPrice  = array.new_float()
var int[]   pivIndex  = array.new_int()
var bool[]  pivIsHigh = array.new_bool()

if isPh
    _idx   = bar_index - strength
    _price = ph
    _isHigh = true
    sz = array.size(pivIndex)
    if sz > 0 and array.get(pivIndex, sz - 1) == _idx
        oldPrice = array.get(pivPrice, sz - 1)
        newPrice = _isHigh ? math.max(oldPrice, _price) : math.min(oldPrice, _price)
        array.set(pivPrice, sz - 1, newPrice)
        array.set(pivIsHigh, sz - 1, _isHigh)
    else
        array.push(pivPrice, _price)
        array.push(pivIndex, _idx)
        array.push(pivIsHigh, _isHigh)
        if array.size(pivIndex) > 60
            array.shift(pivPrice)
            array.shift(pivIndex)
            array.shift(pivIsHigh)

if isPl
    _idx2   = bar_index - strength
    _price2 = pl
    _isHigh2 = false
    sz2 = array.size(pivIndex)
    if sz2 > 0 and array.get(pivIndex, sz2 - 1) == _idx2
        oldPrice2 = array.get(pivPrice, sz2 - 1)
        newPrice2 = _isHigh2 ? math.max(oldPrice2, _price2) : math.min(oldPrice2, _price2)
        array.set(pivPrice, sz2 - 1, newPrice2)
        array.set(pivIsHigh, sz2 - 1, _isHigh2)
    else
        array.push(pivPrice, _price2)
        array.push(pivIndex, _idx2)
        array.push(pivIsHigh, _isHigh2)
        if array.size(pivIndex) > 60
            array.shift(pivPrice)
            array.shift(pivIndex)
            array.shift(pivIsHigh)

//------------------------ RATIO HELPERS ------------------------//
f_inRange(v, minv, maxv) =>
    not na(v) and v >= minv and v <= maxv

f_ratios(_x, _a, _b, _c, _d) =>
    xa = math.abs(_a - _x)
    ab = math.abs(_b - _a)
    bc = math.abs(_c - _b)
    ad = math.abs(_d - _a)
    cd = math.abs(_d - _c)
    bRetXA = xa == 0.0 ? na : math.abs(_a - _b) / xa
    cRetAB = ab == 0.0 ? na : math.abs(_c - _b) / ab
    dRetXA = xa == 0.0 ? na : ad / xa
    dExtBC = bc == 0.0 ? na : cd / bc
    [bRetXA, cRetAB, dRetXA, dExtBC]

//------------------------ PATTERN CHECKS ------------------------//
// Gartley
f_isGartley(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, gbBMin, gbBMax) and f_inRange(cRetAB, gbCMin, gbCMax) and f_inRange(dRetXA, gbDMin, gbDMax)

// Bat
f_isBat(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, batBMin, batBMax) and f_inRange(cRetAB, batCMin, batCMax) and f_inRange(dRetXA, batDMin, batDMax)

// Butterfly
f_isButterfly(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, btBMin, btBMax) and f_inRange(cRetAB, btCMin, btCMax) and f_inRange(dRetXA, btDMin, btDMax)

// Crab
f_isCrab(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, cbBMin, cbBMax) and f_inRange(cRetAB, cbCMin, cbCMax) and f_inRange(dRetXA, cbDMin, cbDMax)

// Shark
f_isShark(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, shBMin, shBMax) and f_inRange(cRetAB, shCMin, shCMax) and f_inRange(dRetXA, shDMin, shDMax)

// Cypher
f_isCypher(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, cyBMin, cyBMax) and f_inRange(cRetAB, cyCMin, cyCMax) and f_inRange(dRetXA, cyDMin, cyDMax)

// 5-0
f_isFiveZero(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, fzBMin, fzBMax) and f_inRange(cRetAB, fzCMin, fzCMax) and f_inRange(dRetXA, fzDMin, fzDMax)

// AB=CD (3-point pattern)
f_isABCD(_a, _b, _c, _d) =>
    ab = math.abs(_b - _a)
    cd = math.abs(_d - _c)
    ratio = ab == 0.0 ? na : cd / ab
    f_inRange(ratio, abMin, abMax)

// Three Drives (4-point pattern)
f_isThreeDrives(_x, _a, _b, _c, _d) =>
    xa = math.abs(_a - _x)
    ab = math.abs(_b - _a)
    bc = math.abs(_c - _b)
    cd = math.abs(_d - _c)
    ratio1 = xa == 0.0 ? na : ab / xa
    ratio2 = ab == 0.0 ? na : bc / ab
    ratio3 = bc == 0.0 ? na : cd / bc
    f_inRange(ratio1, tdMin, tdMax) and f_inRange(ratio2, tdMin, tdMax) and f_inRange(ratio3, tdMin, tdMax)

// Deep Crab
f_isDeepCrab(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, dcBMin, dcBMax) and f_inRange(cRetAB, dcCMin, dcCMax) and f_inRange(dRetXA, dcDMin, dcDMax)

// Alternative Bat
f_isAltBat(_x, _a, _b, _c, _d) =>
    [bRetXA, cRetAB, dRetXA, _] = f_ratios(_x, _a, _b, _c, _d)
    f_inRange(bRetXA, abBMin2, abBMax2) and f_inRange(cRetAB, abCMin2, abCMax2) and f_inRange(dRetXA, abDMin2, abDMax2)

//------------------------ STATE VARIABLES ------------------------//
var line lnXA = na
var line lnAB = na
var line lnBC = na
var line lnCD = na
var line lnXB = na
var line lnAC = na
var line lnBD = na
var line lnXD = na
var label lblPattern = na

var int    lastDIndex      = na
var string lastPatternName = ""
var bool   lastPatternBull = false
var label[] patternLabels  = array.new<label>()

//------------------------ MAIN DETECTION (CURRENT TF) ------------------------//
szP = array.size(pivIndex)

if szP >= 5
    xIdx = array.get(pivIndex, szP - 5)
    aIdx = array.get(pivIndex, szP - 4)
    bIdx = array.get(pivIndex, szP - 3)
    cIdx = array.get(pivIndex, szP - 2)
    dIdx = array.get(pivIndex, szP - 1)

    xVal = array.get(pivPrice, szP - 5)
    aVal = array.get(pivPrice, szP - 4)
    bVal = array.get(pivPrice, szP - 3)
    cVal = array.get(pivPrice, szP - 2)
    dVal = array.get(pivPrice, szP - 1)

    xHigh = array.get(pivIsHigh, szP - 5)
    aHigh = array.get(pivIsHigh, szP - 4)
    bHigh = array.get(pivIsHigh, szP - 3)
    cHigh = array.get(pivIsHigh, szP - 2)
    dHigh = array.get(pivIsHigh, szP - 1)

    bullCandidate = (not xHigh) and aHigh and (not bHigh) and cHigh and (not dHigh)
    bearCandidate = xHigh and (not aHigh) and bHigh and (not cHigh) and dHigh

    string patternHere = ""
    bool   bullHere    = false

    if bullCandidate or bearCandidate
        isG    = showGartley     and f_isGartley(xVal, aVal, bVal, cVal, dVal)
        isB    = showBat         and f_isBat(xVal, aVal, bVal, cVal, dVal)
        isBt   = showButterfly   and f_isButterfly(xVal, aVal, bVal, cVal, dVal)
        isC    = showCrab        and f_isCrab(xVal, aVal, bVal, cVal, dVal)
        isS    = showShark       and f_isShark(xVal, aVal, bVal, cVal, dVal)
        isCy   = showCypher      and f_isCypher(xVal, aVal, bVal, cVal, dVal)
        isFz   = showFiveZero    and f_isFiveZero(xVal, aVal, bVal, cVal, dVal)
        isAbcd = showABCD        and f_isABCD(aVal, bVal, cVal, dVal)
        isTd   = showThreeDrives and f_isThreeDrives(xVal, aVal, bVal, cVal, dVal)
        isDc   = showDeepCrab    and f_isDeepCrab(xVal, aVal, bVal, cVal, dVal)
        isAb2  = showAltBat      and f_isAltBat(xVal, aVal, bVal, cVal, dVal)

        if isG
            patternHere := "Gartley"
            bullHere    := bullCandidate
        else if isB
            patternHere := "Bat"
            bullHere    := bullCandidate
        else if isBt
            patternHere := "Butterfly"
            bullHere    := bullCandidate
        else if isC
            patternHere := "Crab"
            bullHere    := bullCandidate
        else if isS
            patternHere := "Shark"
            bullHere    := bullCandidate
        else if isCy
            patternHere := "Cypher"
            bullHere    := bullCandidate
        else if isFz
            patternHere := "5-0"
            bullHere    := bullCandidate
        else if isAbcd
            patternHere := "AB=CD"
            bullHere    := bullCandidate
        else if isTd
            patternHere := "Three Drives"
            bullHere    := bullCandidate
        else if isDc
            patternHere := "Deep Crab"
            bullHere    := bullCandidate
        else if isAb2
            patternHere := "Alt Bat"
            bullHere    := bullCandidate

        candidateOK = (bullHere and showBull) or ((not bullHere) and showBear)
        newPattern  = (patternHere != "") and candidateOK and (na(lastDIndex) or dIdx != lastDIndex)

        if newPattern
            if not na(lnXA)
                line.delete(lnXA)
            if not na(lnAB)
                line.delete(lnAB)
            if not na(lnBC)
                line.delete(lnBC)
            if not na(lnCD)
                line.delete(lnCD)
            if not na(lnXB)
                line.delete(lnXB)
            if not na(lnAC)
                line.delete(lnAC)
            if not na(lnBD)
                line.delete(lnBD)
            if not na(lnXD)
                line.delete(lnXD)
            if not na(lblPattern)
                label.delete(lblPattern)

            // BLUE for bullish, RED for bearish
            col = bullHere ? color.new(color.blue, 0) : color.new(color.red, 0)

            // Thicker lines for both bullish (blue) and bearish (red)
            lnXA := line.new(xIdx, xVal, aIdx, aVal, extend = extend.none, color = col, width = 3)
            lnAB := line.new(aIdx, aVal, bIdx, bVal, extend = extend.none, color = col, width = 3)
            lnBC := line.new(bIdx, bVal, cIdx, cVal, extend = extend.none, color = col, width = 3)
            lnCD := line.new(cIdx, cVal, dIdx, dVal, extend = extend.none, color = col, width = 3)
            lnXB := line.new(xIdx, xVal, bIdx, bVal, extend = extend.none, color = col, width = 2, style = line.style_dotted)
            lnAC := line.new(aIdx, aVal, cIdx, cVal, extend = extend.none, color = col, width = 2, style = line.style_dotted)
            lnBD := line.new(bIdx, bVal, dIdx, dVal, extend = extend.none, color = col, width = 2, style = line.style_dotted)
            lnXD := line.new(xIdx, xVal, dIdx, dVal, extend = extend.none, color = col, width = 2, style = line.style_dotted)

            direction   = bullHere ? "Bullish" : "Bearish"
            patternText = direction + " " + patternHere

            lblY       = dVal - syminfo.mintick * 200
            labelStyle = bullHere ? label.style_label_up : label.style_label_down
            lblPattern := label.new(dIdx, lblY, patternText, xloc = xloc.bar_index, yloc = yloc.price, style = labelStyle, textcolor = color.white, color = col)
            array.push(patternLabels, lblPattern)

            if alertOnPattern
                alert(patternText + " found on " + timeframe.period + " timeframe", alert.freq_once_per_bar)

            lastDIndex      := dIdx
            lastPatternName := patternText
            lastPatternBull := bullHere

if array.size(patternLabels) > 10
    oldLabel = array.shift(patternLabels)
    label.delete(oldLabel)

// status dot on top (BLUE for bullish, RED for bearish)
plotchar(not na(lastDIndex), title = "Pattern Found", char = "●", location = location.top, size = size.tiny, color = lastPatternBull ? color.blue : color.red)

//------------------------ MTF DASHBOARD (TOP-RIGHT TABLE) ------------------------//
tf10  = request.security(syminfo.tickerid, "10",  lastPatternName)
tf15  = request.security(syminfo.tickerid, "15",  lastPatternName)
tf30  = request.security(syminfo.tickerid, "30",  lastPatternName)
tf60  = request.security(syminfo.tickerid, "60",  lastPatternName)
tf120 = request.security(syminfo.tickerid, "120", lastPatternName)
tf240 = request.security(syminfo.tickerid, "240", lastPatternName)
tfD   = request.security(syminfo.tickerid, "D",   lastPatternName)
tfW   = request.security(syminfo.tickerid, "W",   lastPatternName)

f_show(p) =>
    na(p) or p == "" ? "None" : p

f_color(txt) =>
    _t = na(txt) ? "" : txt
    isBull = str.substring(_t, 0, 7) == "Bullish"
    isBear = str.substring(_t, 0, 7) == "Bearish"
    _t == "None" or _t == "" ? color.gray : isBull ? color.blue : isBear ? color.red : color.white

var table dashTable = table.new(position.top_right, 2, 12, border_width = 1)

if showMTFDashboard
    if barstate.isfirst
        table.cell(dashTable, 0, 3, "TF",      text_color = color.white)
        table.cell(dashTable, 1, 3, "Pattern", text_color = color.white)

        table.cell(dashTable, 0, 4, "10m",  text_color = color.white)
        table.cell(dashTable, 0, 5, "15m",  text_color = color.white)
        table.cell(dashTable, 0, 6, "30m",  text_color = color.white)
        table.cell(dashTable, 0, 7, "1H",  text_color = color.white)
        table.cell(dashTable, 0, 8, "2H", text_color = color.white)
        table.cell(dashTable, 0, 9, "4H", text_color = color.white)
        table.cell(dashTable, 0, 10, "1D",  text_color = color.white)
        table.cell(dashTable, 0, 11, "1W",  text_color = color.white)

    if barstate.islast
        t10  = f_show(tf10)
        t15  = f_show(tf15)
        t30  = f_show(tf30)
        t60  = f_show(tf60)
        t120 = f_show(tf120)
        t240 = f_show(tf240)
        tD   = f_show(tfD)
        tW   = f_show(tfW)

        table.cell(dashTable, 1, 4, t10,  text_color = f_color(t10))
        table.cell(dashTable, 1, 5, t15,  text_color = f_color(t15))
        table.cell(dashTable, 1, 6, t30,  text_color = f_color(t30))
        table.cell(dashTable, 1, 7, t60,  text_color = f_color(t60))
        table.cell(dashTable, 1, 8, t120, text_color = f_color(t120))
        table.cell(dashTable, 1, 9, t240, text_color = f_color(t240))
        table.cell(dashTable, 1, 10, tD,  text_color = f_color(tD))
        table.cell(dashTable, 1, 11, tW,  text_color = f_color(tW))
